/******************************************************************************

  Copyright (C), 2012-2016, ZHANGYA

 ******************************************************************************
  File Name     : debug.h
  Version       : Initial Draft
  Author        : zhangya
  Created       : 2024/2/3
  Last Modified :
  Description   : debug.h
  Function List :
  History       :
  1.Date        : 2024/2/3
    Author      : zhangya
    Modification: Created file

******************************************************************************/
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include "main.h"
#include "SEGGER_RTT.h"

#ifdef __cplusplus
extern "C" {
#endif

/*--------------------------------------------------------------------*
 * $external variables                           *
 *--------------------------------------------------------------------*/
#define	MAX_TRACE_STR_LEN           	(32)

/*--------------------------------------------------------------------*
 * $external routine prototypes                  *
 *--------------------------------------------------------------------*/

#if (DEBUG_EN > 0)
 #define DEBUG_STR(_fmt)            		debug_string(_fmt)
 #define DEBUG_PRINTF(...)					SEGGER_RTT_printf(0,__VA_ARGS__)
 #define DEBUG_INFO(...)      				debug_info(__VA_ARGS__)
 #define DEBUG_ERR(...)						debug_error(__FILE__, __LINE__, __VA_ARGS__)
 #define DEBUG_BUF_U8(_des, _buf, _len) 	debug_buffer_u8(_des, _buf, _len)
 #define DEBUG_BUF_U16(_des, _buf, _len) 	debug_buffer_u16(_des, _buf, _len)
 #define DEBUG_BUF_U32(_des, _buf, _len) 	debug_buffer_u32(_des, _buf, _len)
#else
 #define DEBUG_STR(_fmt)
 #define DEBUG_INFO(...)
 #define DEBUG_ERR(...)
 #define DEBUG_BUF_U8(_des, _buf, _len)
 #define DEBUG_BUF_U16(_des, _buf, _len)
 #define DEBUG_BUF_U32(_des, _buf, _len)
#endif

/*--------------------------------------------------------------------*
 * $internal routine prototypes                  *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $project-wide global variables                *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $module-wide global variables                 *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $constants                                    *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $macros                                       *
 *--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 * $routines' implementations                    *
 *--------------------------------------------------------------------*/

void debug_init(void);

#if (DEBUG_EN > 0)
void debug_error(const char * file, const long line, const char * format, ...);
void debug_info(const char * format, ...);
void debug_string(const char * str);

void debug_buffer_u8(const char * pDes, const uint8_t * pBuf, const uint16_t bufLen);
void debug_buffer_u16(const char * pDes, const uint16_t * pBuf, const uint16_t bufLen);
void debug_buffer_u32(const char * pDes, const uint32_t * pBuf, const uint16_t bufLen);
#endif

#ifdef __cplusplus
}
#endif


#endif //#ifndef _DEBUG_H_

